

package com.googlecode.equalsnhashcode;

import com.googlecode.equalsnhashcode.utils.Lists;
import com.intellij.codeInspection.InspectionManager;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.psi.PsiField;

import java.util.Collections;
import java.util.List;

public class EqualsHashcodeProblemDescriptor {
    private InspectionManager inspectionManager;
    private String message;

    public EqualsHashcodeProblemDescriptor(InspectionManager inspectionManager, String message) {
        this.inspectionManager = inspectionManager;
        this.message = message;
    }

    public List<ProblemDescriptor> problemDescriptorsFor(List<PsiField> psiFields) {
        if (psiFields.isEmpty())
            return Collections.emptyList();
        List<ProblemDescriptor> problemDescriptors = Lists.create();
        for (PsiField field : psiFields) {
            problemDescriptors.add(inspectionManager.createProblemDescriptor(field,
                    String.format(message, field.getName()), new GenerateEqualsHashcodeQuickFix(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
        }
        return problemDescriptors;
    }
}
